package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        int currentSize = bookList.getUsedSize();
        // 展示图书
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            System.out.println(book);
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅图书的名字");
        String name = scanner.next();

        // 遍历图书数组
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                if (!book.getBorrowed()) {
                    System.out.println("借阅成功");
                    book.setBorrowed(true);
                    return;
                }
                System.out.println("图书已被借阅");
                return;
            }
        }
        System.out.println("没有找到要被借阅的图书");
    }
}
